import { parseString } from "../utils/float";

export function parseHeight(height: number | string) {
	if (typeof height === "string") {
		if (height.includes("l")) {
			height = height.replaceAll("l", "1");
		}

		if (height.includes("z")) {
			height = height.replaceAll("z", "2");
		}
		
		if (height.includes("*")) {
			return replaceBadChar(height, "*");
		}

		if (height.includes("米")) {
			return replaceBadChar(height, "米");
		}

		if (height.includes(",")) {
			return replaceBadChar(height, ",");
		}

		if (height.includes("。")) {
			return replaceBadChar(height, ",");
		}
	}
	return checkHeight(parseString(height));
}

function replaceBadChar(height: string, char: string) {
	return 100 * parseFloat(height.replaceAll(char, "."));
}

function checkHeight(height: number) {
	if (height < 2) {
		return height * 100;
	}

	if (height < 30) {
		return height * 10;
	}

	return height;
}
